package com.hspedu.encap;

public class Account {

    private String name;
    private double balance;
    private String pwd;

    //无参构造器
    public Account() {
    }

    //有参构造器
    public Account(String name, double balance, String pwd) {
        setName(name);
        setBalance(balance);
        setKey(pwd);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        if (name.length() >= 2 && name.length() <= 4) {
            this.name = name;
        } else {
            System.out.println("名字的长度不对，需要2-4个字符，给默认名字");
            this.name = "无名氏";
        }
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        if (balance > 20) {
            this.balance = balance;
        } else {
            System.out.println("余额不足，需要大于20，默认为0");
        }
    }

    public String getKey() {
        return pwd;
    }

    public void setKey(String pwd) {
        if (pwd.length() == 6) {
            this.pwd = pwd;
        } else {
            System.out.println("密码不对，密码只能为6位，默认000000");
            this.pwd = "000000";
        }
    }

    //显示账户信息
    public String info() {
        return "你的信息为：name=" + name + " balance=" + balance + " key=" + pwd;
    }

}
